﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Dubs_Finder.Model;
using Dubs_Finder.ViewModel;

namespace Dubs_Finder.View
{
    /// <summary>
    /// Interaction logic for SpecificDubViewUserControl.xaml
    /// </summary>
    public partial class SpecificDubViewUserControl : UserControl
    {
        public SpecificDubViewUserControl()
        {
            InitializeComponent();
        }

        private void menuItem_FileLocation_Click(object sender, RoutedEventArgs e)
        {
            FileWrapper selectedItem = LVSelectedDub.SelectedItem as FileWrapper;
            MainViewModel mvm = new ViewModelLocator().Main;
            mvm.OpenLocation(selectedItem);
        }

        private void menuItem_SetPrimary_Click(object sender, RoutedEventArgs e)
        {
            FileWrapper selectedItem = LVSelectedDub.SelectedItem as FileWrapper;
            MainViewModel mvm = new ViewModelLocator().Main;
            mvm.MarkFile(selectedItem);
        }

        private void menuItem_DeleteFile_Click(object sender, RoutedEventArgs e)
        {
            FileWrapper selectedItem = LVSelectedDub.SelectedItem as FileWrapper;
            MainViewModel mvm = new ViewModelLocator().Main;
            mvm.OpenLocation(selectedItem);
        }

        private void TextBlock_FileName_IsMouseDirectlyOverChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            bool isMouseOver = (bool)e.NewValue;
            if (!isMouseOver)
                return;
            TextBlock textBlock = (TextBlock)sender;
            textBlock.Measure(Size.Parse("150000,0"));
            bool needed = textBlock.DesiredSize.Width > SDFileNameCol.ActualWidth;
            ((ToolTip)textBlock.ToolTip).Visibility =
                needed ? Visibility.Visible : Visibility.Collapsed;
        }

        private void TextBlock_FilePath_IsMouseDirectlyOverChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            bool isMouseOver = (bool)e.NewValue;
            if (!isMouseOver)
                return;
            TextBlock textBlock = (TextBlock)sender;
            textBlock.Measure(Size.Parse("150000,0"));
            bool needed = textBlock.DesiredSize.Width > SDFilePathCol.ActualWidth;
            ((ToolTip)textBlock.ToolTip).Visibility =
                needed ? Visibility.Visible : Visibility.Collapsed;
        }
    }
}
